#ifndef FOC_RUN_H
#define FOC_RUN_H

#include "main.h"
#include "RS485.h"
#include "IQ_math.h"

//#define EN_GATE_SET				HAL_GPIO_WritePin(EN_GATE_GPIO_Port, \
//									EN_GATE_Pin, GPIO_PIN_SET)
//#define EN_GATE_RESET			HAL_GPIO_WritePin(EN_GATE_GPIO_Port, \
//									EN_GATE_Pin, GPIO_PIN_RESET)

#define LED_DRV_SET				HAL_GPIO_WritePin(LED_GPIO_Port, \
									LED_Pin, GPIO_PIN_SET)
#define LED_DRV_RESET			HAL_GPIO_WritePin(LED_GPIO_Port, \
									LED_Pin, GPIO_PIN_RESET)

//#define DISCHARGE_MOS_SET		HAL_GPIO_WritePin(DISCHARGE_MOS_GPIO_Port, \
//									DISCHARGE_MOS_Pin, GPIO_PIN_SET)
//#define DISCHARGE_MOS_RESET		HAL_GPIO_WritePin(DISCHARGE_MOS_GPIO_Port, \
//									DISCHARGE_MOS_Pin, GPIO_PIN_RESET)

//#define READ_NFAULT				HAL_GPIO_ReadPin(nFAULT_GPIO_Port, \
//									nFAULT_Pin)
#define READ_NOCTW				HAL_GPIO_ReadPin(GPIOB, \
									GPIO_PIN_12)
									
#define PWM_PERIOD			 ((uint16_t)3599)
#define PWM_HalfPerMax   ((uint16_t)PWM_PERIOD/2)

#define PWM_FREQ  10000       //10KHZ中断频率

typedef struct{
	 
   int32_t  VBUS;	      //电机母线电压
	 int32_t  Current_Rating;	      //电机额定电流
	 int32_t  Phase_L;    //相电感
	 int32_t  Phase_R;    //相电阻
	 int32_t  Flux;       //磁链
	 int32_t  Pole_Pairs;  //极对数
	
	 int32_t  Rotor_inertia;  //转动惯量
	
}Motor_Params_t;
extern Motor_Params_t Motor_Params;
#define Motor_Params_DEFAULTS  {24,3,0,0,0,0,0}

extern stMcInfo mc_info;
extern volatile int16_t comm[6];
extern  float time_us;
extern  void (* func_ptr)(ADC_HandleTypeDef *hadc);


void ParaInit(void);		// parameters initialization.
void Svpwm_Outpwm(void);
uint32_t IF_id_RUN(uint16_t eleangle_step, uint16_t Id_ref);
uint32_t IF_RUN(uint16_t RPM_ref, uint16_t Iq_ref, uint16_t Time_ms);
uint32_t VF_RUN(uint16_t RPM_ref, uint32_t Uq_ref, uint16_t Time_ms);
#endif
